dojo.provide("common.clazz.XmlReader");
dojo.require("dojox.xml.parser");
/**
 * Usage:
 * <code>
 *   var menuReader=new common.clazz.XmlReader("config/menu-config.xml");
 *   menuReader.loadThenCallback(myCallback);
 * </code>
 * <code>  
 *   function myCallback(xmlDoc) {
 *     var myNodeTag=dojo.query("aNodeTag", xmlDoc);
 *     console.log(myNodeTag);
 *   }
 * </code>
 */
dojo.declare("common.clazz.XmlReader",null,{
  
  srcUrl: null,
  resultDoc: null,
  
  constructor: function(src_url){
    srcUrl=src_url;
  },
  
  loadThenCallback: function(callback){
  //The parameters to pass to xhrGet and the url of the xml file.
    var xhrArgs = {
      url: srcUrl,
      //preventCache: true,
	  handleAs: "xml",
	  timeout: 10000, //give up after 10 seconds
	  load: function(response){
	    //resultDoc = response.documentElement;
		resultDoc = response;
		//debugXmlDoc(resultDoc);
    	callback(resultDoc); //Handle result
	  },
	  error: function(err){
	    alert("Error loading > "+srcUrl+": "+err);
	  }
    };
    //Initiate the async call.
    dojo.xhrGet(xhrArgs);
  }
});